Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

androidApp/src/main/kotlin/org/meshtastic/app/map/MapLayer.kt 83a778a842822a709c80eacf137fb09d0aab5ae8 (83a778a8) Text, 6.35 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.app.map

Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787android.net.Uri
Tff7b72import T7ee787android.provider.OpenableColumns
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787org.meshtastic.core.common.util.nowMillis
Tff7b72import T7ee787kotlin.uuid.Uuid

T8b949e/**
* Flavor-neutral map-layer model shared by the Google (Google Maps data layer) and F-Droid (OSMdroid overlay) flavors.
* Only the final overlay draw is flavor-specific; the layer list, storage, and import logic live in [MapLayersManager].
*/
Tff7b72enum Tff7b72class T56d364LayerType Tb4b4b4{
Te6edf3KMLTb4b4b4,
Te6edf3GEOJSONTb4b4b4,

T8b949e/**
* A Site Planner coverage estimate. GeoJSON on the wire and parsed as such, but tracked as its own type so the
* layers sheet can distinguish an estimate we generated from a GeoJSON file the user imported.
*/
Te6edf3COVERAGETb4b4b4,
Tb4b4b4}

Tff7b72data Tff7b72class T56d364MapLayerItemTb4b4b4(
Tff7b72val Te6edf3idTb4b4b4: Tffa657String Tff7b72= Te6edf3UuidTb4b4b4.Te6edf3randomTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3toStringTb4b4b4(Tb4b4b4)Tb4b4b4,
Tff7b72val Te6edf3nameTb4b4b4: Tffa657StringTb4b4b4,
Tff7b72val Te6edf3uriTb4b4b4: Te6edf3Uri? Tff7b72= Tff7b72nullTb4b4b4,
Tff7b72val Te6edf3isVisibleTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72trueTb4b4b4,
Tff7b72val Te6edf3layerTypeTb4b4b4: Te6edf3LayerTypeTb4b4b4,
Tff7b72val Te6edf3isNetworkTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4,
T8b949e/** Wall-clock creation time, from the backing file's mtime. Null for network layers, which have no local file. */
Tff7b72val Te6edf3createdAtTb4b4b4: Tffa657Long? Tff7b72= Tff7b72nullTb4b4b4,
T8b949e/** UI indicator: whether a refresh is in flight (drives the sheet/toolbar spinner). */
Tff7b72val Te6edf3isRefreshingTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4,
T8b949e/**
* Monotonic counter bumped on refresh so the flavor renderers reliably re-read the layer. A [StateFlow] conflates
* transient values, so a bounced boolean flag can be missed — an ever-increasing token cannot.
*/
Tff7b72val Te6edf3refreshTokenTb4b4b4: Tffa657Int Tff7b72= T79c0ff0Tb4b4b4,
Tb4b4b4)

Tff7b72private Tff7b72val Te6edf3KML_EXTENSIONS Tff7b72= Te6edf3listOfTb4b4b4(Ta5d6ff"Ta5d6ffkmlTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffkmzTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffvnd.google-earth.kml+xmlTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffvnd.google-earth.kmzTa5d6ff"Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3GEOJSON_EXTENSIONS Tff7b72= Te6edf3listOfTb4b4b4(Ta5d6ff"Ta5d6ffgeojsonTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffjsonTa5d6ff"Tb4b4b4)

T8b949e/** On-disk extension marking a saved coverage estimate, so [LayerType.COVERAGE] survives a restart. */
Tff7b72const Tff7b72val Te6edf3COVERAGE_EXTENSION Tff7b72= Ta5d6ff"Ta5d6ffcoverageTa5d6ff"

T8b949e/**
* Coverage estimates append a random UUID to their on-disk name so two estimates saved under the same title don't
* collide. The layers list rebuilds its display name from that file name, so strip the suffix or the raw UUID shows up
* in the UI.
*/
Tff7b72private Tff7b72val Te6edf3TRAILING_UUID Tff7b72=
Te6edf3RegexTb4b4b4(Ta5d6ff"Ta5d6ff_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$Ta5d6ff"Tb4b4b4, Te6edf3RegexOptionTb4b4b4.Te6edf3IGNORE_CASETb4b4b4)

T8b949e/** Recover a layer's display name from its on-disk file name (sans extension). */
Tff7b72fun Td2a8ffdisplayNameFromFileNameTb4b4b4(Te6edf3fileNameWithoutExtensionTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657String Tff7b72=
Te6edf3fileNameWithoutExtensionTb4b4b4.Te6edf3replaceTb4b4b4(Te6edf3TRAILING_UUIDTb4b4b4, Ta5d6ff"Ta5d6ff"Tb4b4b4)

T8b949e/**
* Characters not allowed in an on-disk layer file name: path separators, so an import can't traverse out of
* `map_layers/`, plus control characters. Everything else — spaces, punctuation, non-Latin scripts — is kept, because
* the list rebuilds a layer's display name from this file name and users should see the name they chose.
*/
Tff7b72private Tff7b72val Te6edf3FILE_NAME_UNSAFE Tff7b72= Te6edf3RegexTb4b4b4(Ta5d6ff"""Ta5d6ff[/Ta5d6ff\\Ta5d6ff\Ta5d6ffp{Cntrl}]Ta5d6ff"""Tb4b4b4)

T8b949e/**
* Longest sanitized base name kept, in characters. Bounds the total path length: the UUID suffix and extension add ~46
* bytes, and a non-Latin name can reach 4 bytes per character, which would otherwise overrun the 255-byte file name
* limit and fail the write.
*/
Tff7b72private Tff7b72const Tff7b72val Te6edf3MAX_BASE_NAME_CHARS Tff7b72= T79c0ff4T79c0ff0

T8b949e/**
* Build the on-disk file name for a layer from its [displayName].
*
* [displayName] is untrusted (a DISPLAY_NAME/lastPathSegment from another app's share/open-with), so separators are
* stripped to keep the write inside `map_layers/`. The UUID suffix is load-bearing, not cosmetic: two layers sharing a
* display name would otherwise resolve to the same path and the second write would truncate the first. It also means a
* name of `..` can never itself be the file name. [displayNameFromFileName] strips it back off for display.
*/
Tff7b72fun Td2a8fflayerFileNameTb4b4b4(Te6edf3displayNameTb4b4b4: Tffa657StringTb4b4b4, Te6edf3extensionTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657String Tb4b4b4{
Tff7b72val Te6edf3safeBase Tff7b72= Te6edf3displayNameTb4b4b4.Te6edf3replaceTb4b4b4(Te6edf3FILE_NAME_UNSAFETb4b4b4, Ta5d6ff"Ta5d6ff_Ta5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3takeTb4b4b4(Te6edf3MAX_BASE_NAME_CHARSTb4b4b4)
Tff7b72return Ta5d6ff"Tffd700${Te6edf3safeBaseTffd700}Ta5d6ff_Tffd700${Te6edf3UuidTb4b4b4.Te6edf3randomTb4b4b4(Tb4b4b4)Tffd700}Ta5d6ff.Tffd700$Te6edf3extensionTa5d6ff"
Tb4b4b4}

T8b949e/**
* Resolve a file extension or MIME subtype (e.g. `geojson`, `vnd.geo+json`) to a [LayerType], or null if unsupported.
*/
Tff7b72fun Td2a8ffresolveLayerTypeTb4b4b4(Te6edf3extensionOrMimeTb4b4b4: Tffa657String?Tb4b4b4)Tb4b4b4: Te6edf3LayerType? Tff7b72= Tff7b72when Tb4b4b4(Te6edf3extensionOrMimeTff7b72?.Te6edf3lowercaseTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72in Te6edf3KML_EXTENSIONS Tff7b72-Tff7b72> Te6edf3LayerTypeTb4b4b4.Te6edf3KML

Tff7b72in Te6edf3GEOJSON_EXTENSIONS Tff7b72-Tff7b72> Te6edf3LayerTypeTb4b4b4.Te6edf3GEOJSON

Te6edf3COVERAGE_EXTENSION Tff7b72-Tff7b72> Te6edf3LayerTypeTb4b4b4.Te6edf3COVERAGE

T8b949e// MIME subtypes the content resolver may report for GeoJSON that aren't a bare "geojson"/"json".
Ta5d6ff"Ta5d6ffgeo+jsonTa5d6ff"Tb4b4b4,
Ta5d6ff"Ta5d6ffvnd.geo+jsonTa5d6ff"Tb4b4b4,
Tff7b72-Tff7b72> Te6edf3LayerTypeTb4b4b4.Te6edf3GEOJSON

Tff7b72else Tff7b72-Tff7b72> Tff7b72null
Tb4b4b4}

T8b949e/**
* Resolve a display file name for [this] URI, querying the content resolver for `content://` URIs. Untrusted providers
* (share/open-with from other apps) can throw or return a null display name, so guard both and fall back to the URI's
* last path segment.
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffNestedBlockDepthTa5d6ff"Tb4b4b4)
Tff7b72fun Te6edf3UriTb4b4b4.Td2a8ffgetFileNameTb4b4b4(Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4)Tb4b4b4: Tffa657String Tb4b4b4{
Tff7b72var Te6edf3name Tff7b72= Te6edf3lastPathSegment Tff7b72?: Ta5d6ff"Ta5d6fflayer_Tffd700$Te6edf3nowMillisTa5d6ff"
Tff7b72if Tb4b4b4(Te6edf3scheme Tff7b72=Tff7b72= Ta5d6ff"Ta5d6ffcontentTa5d6ff"Tb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3contextTb4b4b4.Te6edf3contentResolverTb4b4b4.Te6edf3queryTb4b4b4(Tff7b72thisTb4b4b4, Tff7b72nullTb4b4b4, Tff7b72nullTb4b4b4, Tff7b72nullTb4b4b4, Tff7b72nullTb4b4b4)Tff7b72?.Te6edf3use Tb4b4b4{ Te6edf3cursor Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3cursorTb4b4b4.Te6edf3moveToFirstTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3displayNameIndex Tff7b72= Te6edf3cursorTb4b4b4.Te6edf3getColumnIndexTb4b4b4(Te6edf3OpenableColumnsTb4b4b4.Te6edf3DISPLAY_NAMETb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3displayNameIndex Tff7b72!Tff7b72= Tff7b72-T79c0ff1Tb4b4b4) Tb4b4b4{
Te6edf3cursorTb4b4b4.Te6edf3getStringTb4b4b4(Te6edf3displayNameIndexTb4b4b4)Tff7b72?.Te6edf3let Tb4b4b4{ Te6edf3name Tff7b72= Tffa657it Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
T8b949e// Keep the lastPathSegment fallback assigned above rather than crashing the import.
Te6edf3LoggerTb4b4b4.Te6edf3withTagTb4b4b4(Ta5d6ff"Ta5d6ffMapLayerTa5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffFailed to resolve display name for content URI; using fallbackTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tff7b72return Te6edf3name
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s